package com.bank.conrtoller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bank.entity.Account;
import com.bank.service.AccountService;

/*账户信息主控制类*/
@Controller
public class AccountController  extends BaseController{

	Logger logger = Logger.getLogger(AccountController.class);
	
	@Autowired
	AccountService accountService;
	
	
	@RequestMapping(value="doOpenAccount.do",method = RequestMethod.POST)
	public @ResponseBody Map<String, Object> doOpenAccount(Account account, HttpServletRequest request){
		logger.debug("customer_number"+account.getCustomer_number());
		accountService.openAccount(account, request);
		return this.setAndGetSuccess();
	}
	
	//更新账户状态
	@RequestMapping(value="doUpdateAccountStatus.do", method=RequestMethod.POST)
	public @ResponseBody Map<String,Object> doUpdateAccountStatus(@RequestBody Map<String,Object> params){
		String number = (String) params.get("number");
		accountService.updateAccount(number);
		return this.setAndGetSuccess();
	}
	
	@RequestMapping(value="doQueryAccount.do", method=RequestMethod.POST)
	public @ResponseBody Map<String, Object> doQueryAccount(@RequestBody Map<String,Object> params)
	{	
		String number = (String) params.get("number");
		Account account = accountService.getAccount(number);
		if(account==null){
			return this.setAndGetFailed();
		}
		this.setMapValue("number",  account.getNumber());
		this.setMapValue("currency", account.getCurrency());
		this.setMapValue("senior_oir", account.getSenior_oir());
		this.setMapValue("accounting_ori", account.getAccounting_ori());
		this.setMapValue("balance", account.getBalance());
		this.setMapValue("customer_number", account.getCustomer_number());
		this.setMapValue("customer_name", account.getCustomer_name());
		return this.setAndGetSuccess();
	}
	
	/*
	@RequestMapping(value="/doAccountList.do", method=RequestMethod.POST)
	public @ResponseBody Map<String,Object>  doListAccount(@RequestBody Map<String,Object> params)
	{
		String customer_number = (String)params.get("customer_number");
		String number  = (String)params.get("number");
		String senior_oir = (String)params.get("senior_oir");
		String customer_name = (String)params.get("customer_name");
		String offset = (String)params.get("offset");
		String limit = (String)params.get("limit");
		logger.debug("customer_number"+customer_number);
		logger.debug("number"+number);
		logger.debug("senior_oir"+senior_oir);
		logger.debug("customer_name"+customer_name);
		logger.debug("offset"+offset);
		logger.debug("limit"+limit);
		List<Object> value = accountService.getAccountLst(params);
		this.setMapListValue("data", value);
		return this.setAndGetSuccess();
	}*/
	@RequestMapping(value="/doAccountList.do", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public @ResponseBody Map<String,Object>  doListAccount(@RequestBody Map<String,Object> params)
	{
		List<Object> value = accountService.getAccountList(params);
		Integer total = accountService.getAccountListCount(params);
		this.setMapValue("total", total);
		this.setMapListValue("data", value);
		return this.returnMap();
	}
	

}
